package com.archgeek.java.conc;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
 * @author pizhihui
 * @date 2024-03-21 13:39
 */

class MyNumber {
    volatile int i;

    public void addNumber() {
        i++;
    }
}

public class NumberPlusPlusDemo {

    public static void main(String[] args) throws IOException {



        MyNumber myNumber = new MyNumber();
        for (int i = 1; i <= 10; i++) {
            new Thread(() -> {
                for (int j = 1; j <= 1000; j++) {
                    myNumber.addNumber();
                }
            }, "t" + i).start();

        }

        try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); }

        System.out.println(Thread.currentThread().getName() + "..." + myNumber.i);


    }

}
